package com.bestcem.xm.ticket.controller.convert;

import com.bestcem.xm.ticket.controller.vo.ticket.TicketPageVO;
import com.bestcem.xm.ticket.entity.mongo.Ticket;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.LinkedList;

/**
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2022/2/18 15:10
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TicketVOConvert {

    @Nullable
    public static TicketPageVO entityToTicketPageVO(Ticket entity) {
        if (entity == null) {
            return null;
        }

        TicketPageVO data = new TicketPageVO();
        data.setId(entity.getId());
        data.setTicketNo(entity.getTicketNo());
        data.setRegionName(entity.getRegionName());
        data.setSurveyTitle(entity.getSurveyTitle());
        data.setStatus(entity.getStatus());
        data.setAlertRuleIds(entity.getAlertRuleIds());
        if (CollectionUtils.isEmpty(data.getAlertRuleIds())) {
            data.setAlertRuleIds(new ArrayList<>());
        }
        data.setClosedDate(entity.getClosedDate());
        data.setTicketFailedTime(entity.getTicketFailedTime());
        data.setTicketFinishTime(entity.getTicketFinishTime());
        data.setHasFollowOverdue(entity.getHasFollowOverdue());
        data.setTicketDeadline(entity.getTicketDeadline());
        data.setFollowDeadline(entity.getFollowDeadline());
        data.setAuditDeadline(entity.getAuditDeadline());
        data.setHasAuditOverdue(entity.getHasAuditOverdue());
        data.setType(entity.getType());
        data.setCurFollowUserId(entity.getCurFollowUserId());
        if (CollectionUtils.isEmpty(data.getCurFollowUserId())) {
            data.setCurFollowUserId(new ArrayList<>());
        }
        data.setCreatedId(entity.getCreatedId());
        data.setCreatedDate(entity.getCreatedDate());
        data.setUpdatedDate(entity.getUpdatedDate());
        data.setCreatedName(entity.getCreatedName());
        data.setOperationType(entity.getOperationType());
        // 工单满足的触发条件的名称 2022-02-18 行动新增条件名称需求新增
        data.setTriggerNames(entity.getTriggerNames());
        if (CollectionUtils.isEmpty(data.getTriggerNames())) {
            data.setTriggerNames(new LinkedList<>());
        }
        return data;
    }
}
